package com.yyoo.doc.mypdf.builder;

import com.lowagie.text.Element;
import com.lowagie.text.HeaderFooter;
import com.lowagie.text.Phrase;

/**
 * 页眉页脚
 *
 * @author zzy
 */
public class PdfHeaderFooterBuilder extends PdfElementBuilder {
    @Override
    public Element build() {

        Phrase befor = getPhrase("befor");
        Phrase after = getPhrase("after");

        HeaderFooter footer = new HeaderFooter(befor, after);
        footer.setAlignment(getTextAlign());

        footer.setBorderWidth(0);
        setBorderColor(footer);
        setBorderWidth(footer);
        setBackgroundColor(footer);

        return footer;
    }

    /**
     * 获取属性配置的短语
     * @param attrName 属性名，取值为 befor 或 after
     * @return
     */
    protected Phrase getPhrase(String attrName){
        String attribute = getHtmlEl().getAttributeValue(attrName);

        if(attribute != null){
            return new Phrase(attribute,getFont());
        }

        return null;
    }

}
